///
/// 错误类型
///
enum HttpErrorType {
  ///默认错误
  defaultError,

  ///返回数据为空
  dataEmpty,

  ///状态码错误
  statusError,

  ///网络错误
  networkTimeOutError,

  ///授权错误(未登录、token过期等)
  unauthorizedError
}

///
/// 错误状态
///
class AppHttpException implements Exception {
  HttpErrorType _errorType;

  HttpErrorType get errorType => _errorType;

  String message;
  String errorMessage;

  AppHttpException(this._errorType, {this.message, this.errorMessage}) {
    _errorType ??= HttpErrorType.defaultError;
    message ??= "";
    errorMessage ??= "";
  }

  bool get isDefaultError => _errorType == HttpErrorType.defaultError;

  bool get isNetworkTimeOut => _errorType == HttpErrorType.networkTimeOutError;

  bool get isUnauthorized => _errorType == HttpErrorType.unauthorizedError;

  @override
  String toString() {
    return message;
  }
}
